apiready = function () {
  api.parseTapmode();
  FastClick.attach(document.body);
  var header = $api.byId('aui-header');
  $api.fixStatusBar(header);
  var pageLogin = new Vue({
      el: '#pageLogin',
      data: {
        type: 1,
        sendingcode:0
      },
      created: function() {

      },
     methods: {
        login:function(){

          var post={};
          //手机号登陆
          if(this.type==1){
              post.phone = $("#pageLogin #phone").val();
              post.code = $("#code").val();
          }
          //账号密码
          if(this.type==2){
            post.user_name = $("#user_name").val();
            post.password = $("#password").val();
          }

          app.post("apiv2/user/login",post,function(res){
             if(res.code!=200){
                app.alert(res.msg);
                return ;
             }
             app.setUserInfo(res.data);
             openFrame("index","../index.html");
            //  app.init();
          });
        },
        getCode:function(){
          var i =60;
          var that = this;
          // var that = $("#codeBnt");
          if(this.sendingcode==1){
             return ;
          }
          this.sendingcode = 1;
         //验证码倒计时
          $("#codeBnt").text("重新获取("+i+"s)");
          var t = setInterval(function(){
             i--;
             $("#codeBnt").text("重新获取("+i+"s)");
             if(i==0){
                clearInterval(t);
                $("#codeBnt").text('获取验证码');
                that.sendingcode =0;
             }
            },1000);
          //同步返回结果：
          var appKey = api.loadSecureValue({
              sync: true,
              key: 'appKey'
          });
          var phone = $("#pageLogin #phone").val();

          //加密
          var encrypted = md5(phone+appKey);
          app.get("apiv2/user/getPhoneCode",{phone:phone,sign:encrypted},function(res){
             if(res.code!=200){
                app.alert(res.msg);
                that.sendingcode = 0;
                clearInterval(t);
                $("#codeBnt").text('获取验证码');
               return ;
             }
          });

        },
        loginChange:function(){
           this.type=this.type==1?2:1;
        }
     }
  })
}
